import request from "@/utils/request";
import type {
  Menu,
  Role,
  Permission,
  Account,
  AccountListParams,
  AccountListResponse,
  RoleListParams,
  RoleListResponse,
  MenuListParams,
  MenuListResponse,
  MenuCreateParams,
  MenuUpdateParams,
  DeleteResponse,
  RoleGrantParams,
  UserEditParams,
  OutUsdtList,
  CreateOutUsdtParams,
  ActionList,
  RecordPayListParams,
  RecordPayListResponse,
  CreateBankParams,
} from "./types";

// ### 账户管理

// 获取用户列表（账户列表）
export const getAccountList = (params: AccountListParams) => {
  return request<AccountListResponse>({
    url: "/secure/account/list",
    method: "post",
    data: params,
  });
};

// 新增用户
export const createAccount = (data: Partial<Account>) => {
  return request<{ code: number; msg: string }>({
    url: "/secure/account/create",
    method: "post",
    data,
  });
};

// 编辑用户
export const updateAccount = (data: Partial<UserEditParams>) => {
  return request<{ code: number; msg: string }>({
    url: "/secure/account/update",
    method: "post",
    data,
  });
};

// 删除用户/api/secure/account/del
export const deleteAccount = (data: { id: number }) => {
  return request<DeleteResponse>({
    url: `/secure/account/del`,
    method: "post",
    data,
  });
};

// 重置用户密钥
export const resetUserKey = (data: { uid: number }) => {
  return request<{ code: number; msg: string; data: { key: string } }>({
    url: "/secure/account/restSecret",
    method: "post",
    data,
  });
};

// ### 菜单管理

// 菜单列表
export const getMenuList = (params: MenuListParams) => {
  return request<MenuListResponse>({
    url: "/secure/permission/list",
    method: "post",
    data: params,
  });
};

// 新增菜单
export const createMenu = (data: MenuCreateParams) => {
  return request<Menu>({
    url: "/secure/permission/create",
    method: "post",
    data,
  });
};

// 更新菜单
export const updateMenu = (data: MenuUpdateParams) => {
  return request<Menu>({
    url: `/secure/permission/update`,
    method: "post",
    data,
  });
};
// 删除菜单
export const deleteMenu = (data: { id: number }) => {
  return request<DeleteResponse>({
    url: `/secure/permission/del`,
    method: "post",
    data,
  });
};

// ### 角色管理

// 角色列表
export const getRoleList = (params: RoleListParams) => {
  return request<RoleListResponse>({
    url: "/secure/role/list",
    method: "post",
    data: params,
  });
};

// 更新角色
export const updateRole = (data: {
  id: number;
  name: string;
  permissions: number[];
}) => {
  return request<Role>({
    url: `/secure/role/update`,
    method: "post",
    data,
  });
};

// 用户授权角色
export const grantRolePermissions = (data: RoleGrantParams) => {
  return request<DeleteResponse>({
    url: `/secure/role/grant`,
    method: "post",
    data,
  });
};

// 新增角色
export const createRole = (data: { name: string; permissions: number[] }) => {
  return request<Role>({
    url: "/secure/role/create",
    method: "post",
    data,
  });
};

// 角色菜单/权限/api/secure/role/permissions
export const getRolePermissions = (data: { id: number }) => {
  return request<Permission[]>({
    url: `/secure/role/permissions`,
    method: "post",
    data,
  });
};

// 删除角色 /api/secure/role/del
export const deleteRole = (data: { id: number }) => {
  return request({
    url: `/secure/role/del`,
    method: "post",
    data,
  });
};

// 渠道列表/api/secure/paymentConfig/list
export const getPaymentConfigList = (data: {
  dateRange: number;
  type: number;
}) => {
  return request({
    url: `/secure/paymentConfig/list`,
    method: "post",
    data,
  });
};

// 渠道-用户列表/api/secure/paymentConfig/relation
export const getPaymentConfigRelation = (data: { parameter: string }) => {
  return request({
    url: `/secure/paymentConfig/relation`,
    method: "post",
    data,
  });
};

// 对接信息/api/secure/docking/info
export const getDockingInfo = () => {
  return request({
    url: `/secure/docking/info`,
    method: "post",
  });
};

// usdt出金列表/api/secure/outUsdt/list
export const getOutUsdtList = (data: any) => {
  return request<{
    data: OutUsdtList[];
    total: number;
  }>({
    url: `/secure/outUsdt/list`,
    method: "post",
    data,
  });
};

// 新增出金/api/secure/outUsdt/create
export const createOutUsdt = (data: CreateOutUsdtParams) => {
  return request<{ code: number; msg: string }>({
    url: `/secure/outUsdt/create`,
    method: "post",
    data,
  });
};

// 出金操作/api/secure/outUsdt/reject
export const rejectOutUsdt = (data: {
  id: number;
  state: number;
  remark: string;
  secretCode: string;
  rate: number;
}) => {
  return request<{ code: number; msg: string }>({
    url: `/secure/outUsdt/reject`,
    method: "post",
    data,
  });
};

// 操作日志/api/secure/oplog/list
export const getActionList = (data: {
  page: number;
  size: number;
  uid: number;
}) => {
  return request<ActionList[]>({
    url: `/secure/oplog/list`,
    method: "post",
    data,
  });
};

// 资金记录列表/api/secure/recordPay/list
export const getRecordPayList = (data: RecordPayListParams) => {
  return request<RecordPayListResponse>({
    url: `/secure/recordPay/list`,
    method: "post",
    data,
  });
};

// Udst入金/api/secure/usdt/list
export const getUdstList = (data: {
  id: number;
  remark: string;
  secretCode: string;
  state: number;
  page: number;
  size: number;
}) => {
  return request({
    url: `/secure/usdt/list`,
    method: "post",
    data,
  });
};

// 银行卡入金/api/secure/bank/list
export const getBankList = (data: {
  id: number;
  remark: string;
  secretCode: string;
  state: number;
}) => {
  return request({
    url: `/secure/bank/list`,
    method: "post",
    data,
  });
};

// web配置/api/secure/webConfig/list
export const getWebconfigList = () => {
  return request({
    url: `/secure/webConfig/list`,
    method: "post",
  });
};

// 新增银行卡入金/api/secure/bank/create
export const createBank = (data: CreateBankParams) => {
  return request<{ code: number; msg: string }>({
    url: `/secure/bank/create`,
    method: "post",
    data,
  });
};

// 银行卡入金操作/api/secure/bank/reject
export const rejectBank = (data: {
  id: number;
  state: number;
  remark: string;
  secretCode: string;
}) => {
  return request<{ code: number; msg: string }>({
    url: `/secure/bank/reject`,
    method: "post",
    data,
  });
};

// usdt入金新增/api/secure/usdt/create
export const createUsdt = (data: { payAddress: string; usdt: number }) => {
  return request<{ code: number; msg: string }>({
    url: `/secure/usdt/create`,
    method: "post",
    data,
  });
};

// usdt入金操作/api/secure/usdt/reject
export const rejectUsdt = (data: {
  id: number;
  state: number;
  remark: string;
  secretCode: string;
}) => {
  return request<{ code: number; msg: string }>({
    url: `/secure/usdt/reject`,
    method: "post",
    data,
  });
};

// web配置编辑/api/secure/webConfig/update
export const updateWebconfig = (data: any) => {
  return request<{ code: number; msg: string }>({
    url: `/secure/webConfig/update`,
    method: "post",
    data,
  });
};
